<template>
  <div class="intstyle">
    <el-card class="box-card">
      <!-- 输入框，和按钮 -->
      <div class="inhead">
        <el-form :model="formDate" @change="changfn1">
          <span class="zixing">关键字</span>
          <el-input v-model="formDate.keyword" size="small" placeholder="请输入关键字" />
          <span class="zixing">状态</span>
          <!-- <el-input v-model="formDate.state" size="small" placeholder="请输入状态" /> -->
          <el-select v-model="formDate.state" style="margin-right:10px;" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
          <el-button @click="changfn1"><span>确认</span></el-button>
          <el-button @click="canckefn1"><span> 取消</span></el-button>

          <el-button type="success" class="btn1" @click="addfn"><span> <i class="el-icon-edit" />新增技巧</span></el-button>
        </el-form>
      </div>
      <!-- 数据提示栏样式 -->
      <div class="sjcount">
        <span><i class="el-icon-info" style="margin:5px;" />数据一共{{ fenye.counts }}条</span>
      </div>
      <!-- 数据主题部分 -->
      <el-card class="cardmain">
        <el-row class="colorone" type="flex">
          <el-col :span="2">序号</el-col>
          <el-col :span="8">文章标题</el-col>
          <el-col :span="2">阅读数</el-col>
          <el-col :span="3">录入人</el-col>
          <el-col :span="4">录入时间</el-col>
          <el-col :span="3">状态</el-col>
          <el-col :span="3">操作</el-col>
        </el-row>
        <div v-if="list">
          <el-row v-for="item,index in list" :key="item.id" type="flex" class="colortwo">
            <el-col :span="2">{{ item.id }}</el-col>
            <el-col :span="8" class="font">{{ item.title }} <span v-if="item.videoURL" style="cursor: pointer;" @click="shipinfn(item,index)"><i class="el-icon-film" style="color:#0000ff" /></span></el-col>
            <el-col :span="2" class="font" style="padding-left:8px;">{{ item.visits }}</el-col>
            <el-col :span="3" class="font">{{ item.username }}</el-col>
            <el-col :span="4" class="font">{{ item.createTime }}</el-col>
            <el-col :span="3" class="font">{{ item.state=== 0? '已启用' :'已禁用' }}</el-col>
            <el-col :span="3">
              <el-link type="primary" :underline="false" class="total" @click="yulanfn(item,index)">预览</el-link>
              <el-link type="primary" :underline="false" class="total" @click="statefn(item,index)">{{ item.state=== 0? '禁用' :'启用' }}</el-link>
              <el-link type="primary" :underline="false" class="total" :disabled="item.state ===1" @click="editfn(item,index)">修改</el-link>
              <el-link type="primary" :underline="false" class="total" :disabled="item.state ===1" @click.prevent="delfn(item,index)">删除</el-link>
            </el-col>
          </el-row>
        </div>
        <div v-else style="color:gray;text-align:center;">
          暂无数据
        </div>
      </el-card>
      <el-pagination
        style="float:right;margin-top:20px;margin-bottom:15px;"
        background
        layout="prev, pager, next"
        :total="fenye.counts"
        :current-page="fenye.page"
        :page-size="fenye.pagesize"
        @current-change="changfn"
      />
    </el-card>
    <!-- <video :src="src" /> -->
    <yulan ref="yulan" :list="list" :indexget="indexget" />
    <xinzeng ref="xinzeng" :list="list" :indexget="indexget" @diaoyong="diaoyong" />
    <xiugai ref="xiugai" :list="list" :indexget2="indexget2" @diaoyong="diaoyong" />
    <meta name="referrer" content="never">
    <shipin ref="shipin" :srcurl="srcurl" @closethis="closethis" />
  </div>
</template>

<script>
import yulan from './zicom/yulan.vue'
import xinzeng from './zicom/xinzeng.vue'
import xiugai from './zicom/xiugai.vue'
import shipin from './zicom/shipin.vue'
import { test, deldatil, statemsg } from '@/api/modules/interview'
export default {
  components: {
    yulan,
    xinzeng,
    xiugai,
    shipin
  },
  data() {
    return {

      flag2: true,
      options: [{
        value: '1',
        label: '禁用'
      }, {
        value: '0',
        label: '开启'
      }],
      formDate: {
        keyword: '',
        state: ''
      },
      // 获取的索引号
      indexget: '',
      indexget2: '',
      list: [],
      list2: [],
      srcurl: '',
      fenye: {
        counts: 0,
        pagesize: 10,
        page: 1
      }
    }
  },
  created() {
    this.getmessage(this.fenye)
  },
  methods: {
    // 关键字状态获取
    async changfn1() {
      console.log(1111)
      this.list = await this.getmessage({ ...this.formDate, page: this.fenye.page, pagesize: this.fenye.pagesize }).items
      if (!this.list) {
        this.flag2 = false
      }
    },
    canckefn1() {
      console.log(2222)
      this.formDate.keyword = ''
      this.formDate.state = ''
    },
    shipinfn(data, index) {
      // return this.$message.error('视频获取失败')
      this.$refs.shipin.shipinflag = true
      console.log(this.list[index].videoURL)
      this.$refs.shipin.video.url = this.list[index].videoURL

      // this.src = 'https://vd2.bdstatic.com/mda-nkjjf0cncxv84ei1/sc/cae_h264/1668951984234874760/mda-nkjjf0cncxv84ei1.mp4?v_from_s=hkapp-haokan-nanjing&auth_key=1669104263-0-0-3449aa181cd237f65e9b33ef0a92e618&bcevod_channel=searchbox_feed&pd=1&cd=0&pt=3&logid=2063150865&vid=11385750018751608240&abtest=&klogid=2063150865'
    },
    closethis() {
       this.$refs.shipin.shipinflag = false
       this.$refs.shipin.video.url = ''
    },
    async diaoyong() {
      await this.getmessage()
    },
    // 新增功能
    addfn() {
      this.$refs.xinzeng.xinzengVisible = true
    },
    // 修改文章
    async editfn(data, index) {
      this.$refs.xiugai.xiugaiVisible = true
      // const res = await editmsg()
      this.indexget2 = index
      this.$refs.xiugai.formDate.title = this.list[index].title
      this.$refs.xiugai.formDate.articleBody = this.list[index].articleBody
      this.$refs.xiugai.formDate.videoURL = this.list[index].videoURL
      this.$refs.xiugai.formDate.id = this.list[index].id
    },
    // 预览功能
    yulanfn(data, index) {
      this.$refs.yulan.yulanVisible = true
      this.indexget = index
    }, // 修改启用禁用状态
    async statefn(msg, index) {
      if (msg.state === 0) {
        this.list[index].state = 1
        msg.state = 1
        await statemsg(msg.id, msg.state)
        this.$message.success('已禁用文章')
      } else if (msg.state === 1) {
        this.list[index].state = 0
        msg.state = 0
        await statemsg(msg.id, msg.state)
        this.$message.success('已启用文章')
      }
    },
    // 修改时间样式
    changetime(date) {
      const year = new Date(date).getFullYear()
      const month1 = new Date(date).getMonth() + 1
      const month = month1 >= 10 ? month1 : '0' + month1
      const data1 = new Date(date).getDate()
      const data = data1 >= 10 ? data1 : '0' + data1
      const HH1 = new Date(date).getHours()
      const HH = HH1 >= 10 ? HH1 : '0' + HH1
      const mm1 = new Date(date).getMinutes()
      const mm = mm1 >= 10 ? mm1 : '0' + mm1
      const ss1 = new Date(date).getSeconds()
      const ss = ss1 >= 10 ? ss1 : '0' + ss1

      const time = year + '-' + month + '-' + data + ' ' + HH + ':' + mm + ':' + ss
      return time
      // console.log(year, month, data, HH, mm, ss)
      // console.log(date)
    },
    changfn(num) {
      console.log(num)
      this.fenye.page = num
      this.getmessage(this.fenye)
    },
    // 获取数据渲染页面
    async getmessage(data) {
      const res = await test(data)
      console.log(res, '000000000000')
      const { items, counts, pagesize, pages, page } = await test(data)

      this.fenye.counts = counts
      this.fenye.pagesize = parseInt(pagesize)
      this.fenye.pages = pages
      this.fenye.page = parseInt(page)
      // console.log(items, '没修改前')
      items.forEach(item => {
        // console.log(item.createTime)
        item.createTime = this.changetime(item.createTime)
      })
      this.list = items
      // this.changetime(items.createTime)
      console.log(this.list, 'list方法')
    },
    // 删除选中文章
    async delfn(data) {
      console.log(data.id)
      this.$confirm('确定删除该篇文章?', '提示', {
        confirmButtonText: '确认', // 确认按钮文字更换
        cancelButtonText: '取消', // 取消按钮文字更换
        type: 'warning'
      }).then(async() => {
        await deldatil(data.id)
        // console.log(res, '000000')
        this.$message.success('删除成功')
        this.getmessage()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.intstyle{
  width: 100%;
  padding: 20px;
}
.font{
  flex-wrap: nowrap;
  overflow: hidden;
  font-size: 15px;
}
 .text {
    font-size: 14px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 100%;
    // padding: 5px;
    // margin: 10px !important;
  }

.inhead{
  height: 50px;
  padding-left: 40px;
}
//span提示
.zixing{
  margin-right:15px ;
  font-weight: 700;
}
//输入框样式
  .el-input{
 width: 180px;
 height: 28px;
 height: 100%;
 margin-right:55px ;
}
//新增技巧按钮
.btn1{
  // margin-left:450px ;
  position: absolute;
  right: 80px;
}
//数据提示栏样式
.sjcount{
background-color: #f4f4f5;
font-size: 13px;
padding-left:20px ;
color: #9d9399;
border-radius: 2px;
}
//数据主题样式
.cardmain{
  margin-top:15px ;
}

//第一行row样式
.colorone{
  width: 100%;
  background-color: #fafafa;
  border-bottom:3px solid #e8e8e8 ;
  height: 53px;
  line-height: 53px;
color: #909399;
font-weight: 700;
}
.colortwo{
   width: 100%;
  // border-bottom:3px solid #e8e8e8 ;
  height: 53px;
  line-height: 53px;
}

//操作栏样式
.total{
  font-size: 13px;
  margin-right: 5px;
  // cursor: pointer;
  color: #409eff;
  border: 0px;
  background-color: white;
}

</style>
